﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using Cofe.Core;
using Cofe.Core.Implements;
using Cofe.Core.Logger;
using Cofe.Core.Security;
using Cofe.Web.Properties;

namespace Cofe.Web
{
    public static class CofeConfig
    {
        public static async Task RegisterCofe()
        {
            //Required for SevenZip support.
            SevenZip.SevenZipCompressor.SetLibraryPath(Settings.Default.DllPath7z);
            SevenZip.SevenZipExtractor.SetLibraryPath(Settings.Default.DllPath7z);

            CofeWsServices.GetMediaFormatter = () => GlobalConfiguration.Configuration.Formatters;

            new ModuleBootStrapper(false,
                new Cofe.Core.RegisterModule(),
                new Cofe.Data.RegisterModule(false, CacheUpdateOptions.Active),
                new Cofe.Web.RegisterModule(),
                new Cofe.IO.RegisterModule(),
                new Cofe.Media.RegisterModule()
                ).Run();
            await CofeServices.RestoreAsync();

            SecurityConfig.GrandAdminAccessToAllVolume();
            CofeServices.CofeSettings.CacheUpdateOptions = CacheUpdateOptions.Active;

            //Start FeedServices (which listen to events and write to log file)
            CofeWsServices.Feeds.GetFeedService<CofeSystemEventArgs>().Updater.Start();

            //new ManualBootStrapperIODBWS(false, false, CacheUpdateOptions.Active).Run();

            GlobalConfiguration.Configuration
                  .Formatters
                  .XmlFormatter.SetSerializer<CofeSystemInfo>(
                      new DataContractSerializer(typeof(CofeSystemInfo),
                          CofeServices.PropertyInterfaceManager.AllCastableContainers));

            //GlobalConfiguration.Configuration
            //      .Formatters
            //      .XmlFormatter.SetSerializer<object>(
            //          new DataContractSerializer(typeof(CofeSystemInfo),
            //              CofeServices.PropertyInterfaceManager.AllCastableContainers));

           
        }
    }
}